package cn.zxf.redis_test.config;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
@AutoConfigureAfter( RedisAutoConfiguration.class )
public class RedisConfiguration {

    @Bean
    public RedisTemplate<String, Object> redisCacheTemplate( LettuceConnectionFactory redisConnectionFactory ) {
        RedisTemplate<String, Object> template = new RedisTemplate<>();
        template.setKeySerializer( new StringRedisSerializer() );
        template.setValueSerializer( new GenericJackson2JsonRedisSerializer() );
        template.setConnectionFactory( redisConnectionFactory );
        return template;
    }

}
